import includeHtml from "./plugins/vite-plugin-include.js";
import {defineConfig, loadEnv} from 'vite';

export default (({mode}) => {
  // console.log('mode', mode, loadEnv(mode, process.cwd()))
   let env = loadEnv(mode, process.cwd())
    console.log(env)
    let config  = {
        lib: {}
    }
    config = {
        outDir: "dist",
        lib:{
            entry: ['src/webcom.js'],
            cssFileName: 'z-webcom',
        }
    }
    if (env.VITE_APP_TITLE === 'server') {
        config = {
            outDir: "../../chatcord/public/app/zcp",
            lib: {
                entry: ['src/webcom.js'],
                cssFileName: 'z-webcom',
            }
        }
    }

    return defineConfig({
      css: {
            postcss: {
                plugins: [
                ]
            }
      },
        plugins: [
            includeHtml
        ],
      server: {
        watch: {
            ignored: /demoes/,
        }
      },
      build:{
          target: "modules",
          minify: false,
          modulePreload: false,
          outDir: config.outDir,
          lib: {
              formats: ["es"],
              ...config.lib,
              fileName: (format, entryName) => `z-${entryName}.${format}.js`,
              postcssOptions: {
                  plugins: [

                  ]
              }
          },
      },
  })
})
